using System.Text.RegularExpressions;

namespace CSharpPro._0930;

public class User
{
    private static string name;
    private static string pwd;
    public void TestPrint1()
    {
        Console.WriteLine("1. 登录 2. 注册 3. 退出");
        int a=int.Parse(Console.ReadLine());
        if (a == 1)
        {
            Console.Write("输入用户名");
            string username = Console.ReadLine();
            Regex regex = new Regex(@"[a-zA-Z0-9_]{3,15}");
            bool isMatch1 = regex.IsMatch(username);
            if (!isMatch1)
            {
                Console.Write("用户名格式不正确");
                TestPrint1();
                return;
            }
            Console.Write("输入密码");
            string userpwd = Console.ReadLine();
            Regex regex1 = new Regex("^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)[a-zA-Z\\d]{6,20}$");
            bool isMatch2 = regex1.IsMatch(userpwd);
            if (!isMatch2)
            {
                Console.Write("密码格式不正确");
                TestPrint1();
                return;
            }
            if (username != name)
            {
                Console.Write("用户名不存在");
                TestPrint1();
                return;
            }
            if (userpwd != pwd)
            {
                Console.Write("密码错误");
                TestPrint1();
                return;
            }
            Console.Write("登录成功，进入首页");
        }
        else if (a == 2)
        {
            Console.Write("输入用户名");
            name = Console.ReadLine();
            Regex regex = new Regex(@"[a-zA-Z0-9_]{3,15}");
            bool isMatch1 = regex.IsMatch(name);
            if (!isMatch1)
            {
                Console.Write("用户名格式不正确");
                TestPrint1();
                return;
            }
            Console.Write("输入密码");
            pwd = Console.ReadLine();
            Regex regex1 = new Regex("^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)[a-zA-Z\\d]{6,20}$");
            bool isMatch2 = regex1.IsMatch(pwd);
            if (!isMatch2)
            {
                Console.Write("密码格式不正确");
                TestPrint1();
                return;
            }
            Console.Write("再次输入密码");
            string pwd2 = Console.ReadLine();
            if (pwd != pwd2)
            {
                Console.Write("两次密码不用");
            }
            TestPrint1();
        }
        else if(a == 3)
        {
            Console.Write("退出");
        }
        else
        {
            Console.Write("输入错误");
            TestPrint1();
        }
    }
}